﻿namespace Domain.Core.ViewModel.Base
{
    public class BaseResponse
    {
        public BaseResponse(StatusCode apiCode = StatusCode.CODE200, string msg = null)
        {
            switch (apiCode)
            {
                case StatusCode.CODE200:
                    {
                        Status = 200;
                        Message = "";
                    }
                    break;
                case StatusCode.CODE401:
                    {
                        Status = 401;
                        Message = "很抱歉，您无权访问该接口，请确保已经登录!";
                    }
                    break;
                case StatusCode.CODE403:
                    {
                        Status = 403;
                        Message = "很抱歉，您的访问权限等级不够，联系管理员!";
                    }
                    break;
                case StatusCode.CODE404:
                    {
                        Status = 404;
                        Message = "资源不存在!";
                    }
                    break;
                case StatusCode.CODE500:
                    {
                        Status = 500;
                        Message = msg;
                    }
                    break;
            }
        }

        public int Status { get; set; } = 200;

        /// <summary>
        /// 
        /// </summary>
        public string Message { get; set; } = "";

        /// <summary>
        /// 
        /// </summary>
        public bool Success  => Status == 200;

        public void SetSuccess(string msg = null)
        {
            Status = 200;
            Message = msg;
        }

        public void SetError(StatusCode apiCode = StatusCode.CODE200, string msg = null)
        {
            Status = 200;
            Message = msg;
        }
    }

    public class BaseResponse<T> : BaseResponse
    {
        /// <summary>
        /// 
        /// </summary>
        public T? Result { get; set; } = default;
        public void SetSuccess(T data = default(T), string msg = null)
        {
            Status = 200;
            Message = msg;
            Result = data;
        }
    }

    public enum StatusCode
    {
        CODE200,
        CODE401,
        CODE403,
        CODE404,
        CODE500
    }
}
